﻿<UserControl x:Class="GSF.TimeSeries.Transport.UI.UserControls.MeasurementGroupUserControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" d:DesignHeight="650" d:DesignWidth="850"
             xmlns:uc="clr-namespace:GSF.TimeSeries.UI.UserControls;assembly=GSF.TimeSeries.UI.WPF"
             xmlns:tsfBinding="clr-namespace:GSF.TimeSeries.UI.Binding;assembly=GSF.TimeSeries.UI"
             xmlns:ui="clr-namespace:GSF.TimeSeries.UI;assembly=GSF.TimeSeries.UI.WPF"
             Background="Transparent">

    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/GSF.TimeSeries.UI.WPF;Component/Resources/CommonResource.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
        
    <StackPanel x:Name="StackPanelManageMeasurementGroup" Orientation="Vertical">
        <StackPanel.Resources>
            <Style TargetType="Grid">
                <Setter Property="Margin" Value="5,0,5,0"/>
            </Style>
        </StackPanel.Resources>

        <Grid x:Name="GridDetailView" DataContext="{tsfBinding:Column Path=CurrentItem}" HorizontalAlignment="Center">
            <Grid.BindingGroup >
                <BindingGroup Name="input"/>
            </Grid.BindingGroup>

            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>

            <ComboBox Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" DataContext="{Binding ElementName=StackPanelManageMeasurementGroup, Path=DataContext}" ItemsSource="{tsfBinding:Column Path=ItemsSource}" SelectedItem="{tsfBinding:Column Path=CurrentItem}" Width="250">
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{tsfBinding:Column Path=Name}" TextAlignment="Left" Padding="1" />
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>

            <Button Grid.Row="0" Grid.Column="3" Width="Auto" HorizontalAlignment="Right" Content="Access Control Precedence" Template="{StaticResource HyperlinkStyleButtonTemplate}" Click="OpenPopupButton_Click" />

            <StackPanel Grid.Row="1" Grid.Column="0" Orientation="Horizontal">
                <TextBlock Text="Name" Style="{StaticResource RequiredLabel}"/>
                <TextBlock Style="{StaticResource RequiredMarker}" />
            </StackPanel>
            <TextBox Grid.Row="1" Grid.Column="1" Text="{tsfBinding:Column Path=Name}" MaxLength="50"/>

            <TextBlock Grid.Row="1" Grid.Column="2" Text="Description" />
            <TextBox Grid.Row="1" Grid.Column="3" Text="{tsfBinding:Column Path=Description}" TextWrapping="Wrap" Width="400"/>

            <TextBlock Grid.Row="2" Grid.Column="2" Text="Filter Expression" VerticalAlignment="Top" />
            <TextBox Grid.Row="2" Grid.Column="3" Width="400" Height="{StaticResource XSmallItemSize}" Text="{tsfBinding:Column Path=FilterExpression}" TextWrapping="Wrap" AcceptsReturn="True" VerticalScrollBarVisibility="Visible" />

        </Grid>

        <uc:DetailViewFooterUserControl DeleteCommand="{Binding DeleteCommand}" ClearCommand="{Binding ClearCommand}" SaveCommand="{Binding SaveCommand}"
            SaveEnabled="{tsfBinding:DataOperation Path=(Validation.HasError)}" HorizontalAlignment="Right" />

        <Grid DataContext="{tsfBinding:Column Path=CurrentItem}" 
                Visibility="{Binding Path=DataContext.CanDelete, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=StackPanel}, Converter={StaticResource ObjectToVisibilityConverter}}">
                    
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <TextBlock Grid.Column="0" Grid.Row="0" Text="Member Measurements" HorizontalAlignment="Left" FontWeight="Bold"/>
            <uc:MeasurementPagerUserControl Grid.Column="0" Grid.Row="1" Name="MemberMeasurementsPager" ItemsPerPage="16" Selectable="True" Searchable="True" ShowPageSize="False" Width="400" VerticalAlignment="Top" Margin="0" Loaded="MemberMeasurementsPager_Loaded" />

            <StackPanel Orientation="Vertical" Grid.Column="1" Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center">
                <Button Content="&gt;&gt;" ToolTip="Remove Measurements" Width="Auto" Margin="2" IsEnabled="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=StackPanel, AncestorLevel=2}, Path=CanSave}" Click="RemoveMeasurementsButton_Click"/>
                <Button Content="&lt;&lt;" ToolTip="Add Measurements" Width="Auto" Margin="2" IsEnabled="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=StackPanel, AncestorLevel=2}, Path=CanSave}" Click="AddMeasurementsButton_Click"/>
            </StackPanel>

            <TextBlock Grid.Column="2" Grid.Row="0" Text="Available Measurements" HorizontalAlignment="Left" FontWeight="Bold"/>
            <uc:MeasurementPagerUserControl Grid.Column="2" Grid.Row="1" Name="AvailableMeasurementsPager" ItemsPerPage="16" Selectable="True" Searchable="True" ShowPageSize="False" Width="400" VerticalAlignment="Top" Margin="0" />
        </Grid>

        <ui:TsfPopup Name="AccessControlPrecedencePopup" Placement="Center" Topmost="False" IsOpen="False">
            <Border CornerRadius="5" BorderThickness="2" Background="White" BorderBrush="Blue">
                <StackPanel>
                    <Button Width="Auto" HorizontalAlignment="Right" Click="ClosePopupButton_Click">
                        <Button.Template>
                            <ControlTemplate>
                                <TextBlock Margin="0" Padding="5" HorizontalAlignment="Center" TextAlignment="Center" FontFamily="Global Sans Serif" FontSize="14" Text="X" Cursor="Hand" />
                            </ControlTemplate>
                        </Button.Template>
                    </Button>

                    <Grid Margin="15">
                        <Grid.Resources>
                            <Style TargetType="TextBlock">
                                <Style.Setters>
                                    <Setter Property="Margin" Value="5" />
                                    <Setter Property="HorizontalAlignment" Value="Center" />
                                    <Setter Property="VerticalAlignment" Value="Center" />
                                    <Setter Property="TextAlignment" Value="Center" />
                                    <Setter Property="TextWrapping" Value="Wrap" />
                                </Style.Setters>
                            </Style>
                        </Grid.Resources>

                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>

                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="300" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>

                        <TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" FontWeight="Bold" Text="Precedence" />
                        <TextBlock Grid.Row="0" Grid.Column="2" FontWeight="Bold" Text="Access Control Type" />
                        <TextBlock Grid.Row="0" Grid.Column="3" FontWeight="Bold" Text="Description" />
                        <TextBlock Grid.Row="0" Grid.Column="4" FontWeight="Bold" Text="Example" />

                        <Grid Grid.Row="1" Grid.Column="0" Grid.RowSpan="4" Margin="0,15">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            
                            <Border Grid.Row="0" BorderBrush="Black" BorderThickness="1" HorizontalAlignment="Center" />
                            <Path Grid.Row="1" Grid.Column="0" Data="M0,0 L5,10 L10,0Z" Stroke="Black" Fill="Black" StrokeThickness="1" HorizontalAlignment="Center" VerticalAlignment="Center" />
                        </Grid>

                        <TextBlock Grid.Row="1" Grid.Column="1">1</TextBlock>
                        <TextBlock Grid.Row="2" Grid.Column="1">2</TextBlock>
                        <TextBlock Grid.Row="3" Grid.Column="1">3</TextBlock>
                        <TextBlock Grid.Row="4" Grid.Column="1">4</TextBlock>

                        <TextBlock Grid.Row="1" Grid.Column="2">Explicit</TextBlock>
                        <TextBlock Grid.Row="2" Grid.Column="2">Group Explicit</TextBlock>
                        <TextBlock Grid.Row="3" Grid.Column="2">Filter Implicit</TextBlock>
                        <TextBlock Grid.Row="4" Grid.Column="2">Group Implicit</TextBlock>

                        <TextBlock Grid.Row="1" Grid.Column="3">Rights are applied directly to signals via measurement pick lists.</TextBlock>
                        <TextBlock Grid.Row="2" Grid.Column="3">Rights are applied by allowing or denying a group of measurements which were explicitly added to the group via measurement pick lists.</TextBlock>
                        <TextBlock Grid.Row="3" Grid.Column="3">Rights are applied using an access control filter applied directly to the subscriber.</TextBlock>
                        <TextBlock Grid.Row="4" Grid.Column="3">Rights are applied by allowing or denying a group of measurements which were implicitly added to the group via a filter expression.</TextBlock>

                        <TextBlock Grid.Row="3" Grid.Column="4">
                            ALLOW WHERE SignalType = 'FREQ';<LineBreak />
                            ALLOW WHERE SignalType = 'DFDT';<LineBreak />
                            DENY WHERE Company = 'GPA'
                        </TextBlock>
                        <TextBlock Grid.Row="4" Grid.Column="4">
                            FILTER ActiveMeasurements<LineBreak />
                            WHERE SignalType = 'FREQ'
                        </TextBlock>
                    </Grid>
                </StackPanel>
            </Border>
        </ui:TsfPopup>
    </StackPanel>    
</UserControl>
